package com.logistics.inventory.entity.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.logistics.inventory.entity.model.InventoryDetailSave;
import com.logistics.inventory.entity.model.UpdStation;
import com.logistics.material.entity.model.MaterialBackRow;
import com.logistics.material.entity.model.MaterialBackSave;
import com.logistics.utils.bean.UserBean;
import com.logistics.utils.tool.DateUtils;
import com.logistics.pick.entity.model.PickDetailSave;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 * 拣配明细
 * </p>
 *
 * @author sun.yang
 * @since 2024-06-27
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("lgs_inventory_detail")
public class InventoryDetail implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    /**
     * 托盘
     */
    private String container;

    /**
     * 序号
     */
    private Integer itemSeqNo;

    /**
     * 物料编码
     */
    private String itemCode;

    /**
     * 任务号
     */
    private String itemWorkcode;

    /**
     * 工序No
     */
    private String itemOpNo;



    /**
     * 物料名称
     */
    private String itemName;

    /**
     * 物料单位
     */
    private String itemUnit;

    /**
     * 数量
     */
    private BigDecimal itemQty;

    /**
     * 创建人组织编码
     */
    private String createOrgCode;

    /**
     * 创建人部门编码
     */
    private String createDepCode;

    /**
     * 创建人
     */
    private String creator;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 修改人
     */
    private String updater;

    /**
     * 修改时间
     */
    private Date updateTime;

    public InventoryDetail(){

    }

    public static InventoryDetail build(UpdStation updStation){
        InventoryDetail inventoryDetail = new InventoryDetail();
        inventoryDetail.setContainer(updStation.getContainerCode());
        inventoryDetail.setUpdater(updStation.getUpdater());
        inventoryDetail.setUpdateTime(DateUtils.stringToDateFormat(updStation.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        return inventoryDetail;
    }

    public static InventoryDetail build(InventoryDetailSave save){
        InventoryDetail inventoryDetail = new InventoryDetail();
        inventoryDetail.setContainer(save.getContainer());
        inventoryDetail.setItemCode(save.getItemCode());
        inventoryDetail.setItemWorkcode(save.getItemWorkCode());
        inventoryDetail.setItemOpNo(save.getItemOpNo());
        inventoryDetail.setItemSeqNo(save.getItemSeqNo());
        inventoryDetail.setItemName(save.getItemName());
        inventoryDetail.setItemUnit(save.getItemUnit());
        inventoryDetail.setItemQty(save.getItemQty());
        inventoryDetail.setCreateDepCode(save.getCreateDepCode());
        inventoryDetail.setCreateOrgCode(save.getCreateOrgCode());
        inventoryDetail.setCreator(save.getCreator());
        inventoryDetail.setCreateTime(DateUtils.stringToDateFormat(save.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        inventoryDetail.setUpdater(save.getUpdater());
        inventoryDetail.setUpdateTime(DateUtils.stringToDateFormat(save.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        return inventoryDetail;
    }

    public static InventoryDetail build(MaterialBackSave save, MaterialBackRow row){
        InventoryDetail inventoryDetail = new InventoryDetail();
        inventoryDetail.setContainer(save.getContainer());
        inventoryDetail.setItemCode(row.getItemCode());
        inventoryDetail.setItemWorkcode(row.getItemWorkCode());
        inventoryDetail.setItemOpNo(row.getSeqNo());
//        inventoryDetail.setItemSeqNo(row.getItemSeqNo());
        inventoryDetail.setItemName(row.getItemName());
        inventoryDetail.setItemUnit(row.getItemUnit());
        inventoryDetail.setItemQty(row.getItemQty());
        inventoryDetail.setCreateDepCode(save.getCreateDepCode());
        inventoryDetail.setCreateOrgCode(save.getCreateOrgCode());
        inventoryDetail.setCreator(save.getCreator());
        inventoryDetail.setCreateTime(DateUtils.stringToDateFormat(save.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        inventoryDetail.setUpdater(save.getUpdater());
        inventoryDetail.setUpdateTime(DateUtils.stringToDateFormat(save.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        return inventoryDetail;
    }

    public InventoryDetail(PickDetailSave save){
        this.createOrgCode = save.getCreateOrgCode();
        this.createDepCode = save.getCreateDepCode();
        this.creator = save.getCreator();
        this.createTime = new Date();
        this.updater = save.getUpdater();
        this.updateTime = new Date();
    }

    public static InventoryDetail build(PickDetailSave save){
        return new InventoryDetail(save);
    }

}
